package br.com.sysmap.dollymockup.client.common.business;

import br.com.sysmap.crux.core.client.formatter.Formatter;
import br.com.sysmap.crux.core.client.formatter.InvalidFormatException;
import br.com.sysmap.crux.core.client.formatter.annotation.FormatterName;
import br.com.sysmap.dollymockup.client.common.i18n.ClientMessages;

/**
 * Formatter for boolean values
 * @author Gesse Dafe
 */
@FormatterName("boolean")
public class BooleanFormatter implements Formatter
{
	/**
	 * @see br.com.sysmap.crux.core.client.formatter.Formatter#format(java.lang.Object)
	 */
	public String format(Object input) throws InvalidFormatException
	{
		if(input != null)
		{
			Boolean bool = (Boolean) input;
			if(bool != null && bool.booleanValue())
			{
				return ClientMessages.instance().yes();
			}
		}
		
		return ClientMessages.instance().no();
	}

	/**
	 * @see br.com.sysmap.crux.core.client.formatter.Formatter#unformat(java.lang.String)
	 */
	public Object unformat(String input) throws InvalidFormatException
	{
		if(ClientMessages.instance().yes().equals(input))
		{
			return Boolean.TRUE;
		}
		
		return Boolean.FALSE;
	}
}